package com.example.demo10_json_login.controller;

import com.example.demo10_json_login.utils.VerifyCode;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.image.BufferedImage;
import java.io.IOException;

@RestController
public class VerifyCodeController {

    @GetMapping("/verifyCode")
    public void verifyCode(HttpSession session, HttpServletResponse response) throws IOException {
        VerifyCode verifyCode = new VerifyCode();
        BufferedImage image = verifyCode.getImage();
        String code = verifyCode.getText();
        session.setAttribute("verify_code",code);
        response.setContentType(MediaType.IMAGE_JPEG_VALUE);
        VerifyCode.output(image,response.getOutputStream());
    }

    @GetMapping("/hello")
    public String hello(){
        return "hello";
    }

}
